package com.example.mybank.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybank.entity.Product;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductMapper extends BaseMapper<Product> {

    @Select("select * from product where " +
            "time_from > now() " +
            "and time_from < date_add(now(), interval #{mins} minute) and is_load=false ;")
    List<Product> getStartInNextXmins(int mins);

    @Select("select * from product " +
            "where time_end < date_sub(now(),interval #{mins} minute )")
    List<Product> getEndPassXmins(int mins);

    @Select("select * from product " +
            "where time_from <= now() and time_end >= now() ")
    List<Product> getBuyable();

    @Update("UPDATE product " +
            "SET count_sale=count_sale+1 " +
            "WHERE id=#{productID}")
    int incrementCount_sale(Long productID);


    @Update("UPDATE product " +
            "SET is_effect=false " +
            "WHERE id=#{productID} and is_effect=true")
    int setUpload(Long productID);


    @Update("UPDATE product " +
            "SET is_load=true " +
            "WHERE id=#{productID} and is_load=false")
    int setdelete(Long productID);

}
